<?php
require_once(ROOTDIR.'classes/basedb.php');

class ShareDB extends BaseDB{
	public function getShareList(){
		$sql = "select * from fanwe_share where share_id<52756 order by share_id desc";
		//$sql = "select * from fanwe_share where share_id=20014";
		$query = $this->_db_reader->query($sql);
		$result = $this->_getAllResultFromQuery($query);
		return $result;
	}
	
	public function getShareSearchList($word){
		$sql = "select * from fanwe_share where content like '%".$word."%' order by share_id desc";
		$query = $this->_db_reader->query($sql);
		$result = $this->_getAllResultFromQuery($query);
		return $result;
	}
	
	public function updateShareCacheData($share_id,$cache_data){
		$save_data = $this->_addSlashes(iconv('utf-8','gbk',$this->_serialize($cache_data)));
		$sql = "update fanwe_share set cache_data=".$save_data." where share_id=".$share_id;
		$this->_db_writer->update($sql);
	}
	
	public function getShareCateId($share_id){
		$sql = "select c.cate_id from fanwe_share_tags a, fanwe_goods_tags b,fanwe_goods_category_tags c where a.tag_name=b.tag_name and b.tag_id=c.tag_id and b.type=3 and a.share_id=".$share_id." and c.cate_id>13";
		$result = $this->_db_reader->get_one($sql);
		if($result){
			return $result['cate_id'];
		}else{
			return 0;
		}
	}
	
	public function deleteShareRelCate($share_id){
		$sql = "delete from fanwe_share_category where share_id=".$share_id;
		$this->_db_writer->update($sql);
	}
	
	public function insertShareRelCate($share_id,$cate_id){
		$sql = "insert into fanwe_share_category(share_id,cate_id) values(".$share_id.",".$cate_id.")";
		$this->_db_writer->update($sql);
	}
	
	
}
?>